#coding:utf-8
from django.forms import ModelForm
from django import forms
from django.contrib.auth.models import User
from models import UserProfile
from django.utils.translation import ugettext_lazy as _

class LoginForm(forms.Form):
    email = forms.CharField(label='邮 箱',widget = forms.TextInput(attrs={'id' : 'email'}))
    password = forms.CharField(label='密 码',widget = forms.PasswordInput(attrs = {'class' : 'text'}))

class RegisterForm(forms.Form):
    email = forms.CharField(label='邮 箱',widget=forms.TextInput(attrs={'class' : 'email'}))
    password = forms.CharField(label='密 码',widget=forms.PasswordInput(attrs={'class' : 'password'}))
    confirm_password = forms.CharField(label='确认密码',widget=forms.PasswordInput(attrs={'class' : 'confirm_password'}))
    username = forms.CharField(max_length = 20,label='昵 称',widget=forms.TextInput(attrs = {'class' : 'username'}))

    def clean_email(self):
        email = self.cleaned_data['email']
        users = User.objects.filter(email__iexact = email)
        if not users:
            return email
        raise forms.ValidationError("该邮箱已经被注册")

class DetailForm(forms.Form):
    username = forms.CharField(max_length = 20,label = '昵 称', widget = forms.TextInput(attrs = {'class' : 'username'}))
    blog = forms.URLField(required = False,label = '个人主页', widget = forms.TextInput(attrs = {'id' : 'blog'}))
    position = forms.CharField(required = False,max_length = 100,label = '方 位',widget = forms.TextInput(attrs = {'class' : 'position'}))
    selfnote = forms.CharField(required = False,label = '简 介',widget = forms.Textarea(attrs = {'placeholder' : '适当的文艺一下，是必须滴...'}))

class ModifyPwdForm(forms.Form):
    oldpassword = forms.CharField(label = '当前密码', widget = forms.PasswordInput(attrs = {'class' : 'oldpassword'}))
    password = forms.CharField(label = '密 码',widget = forms.PasswordInput(attrs = {'class' : 'password'}))
    confirm_password = forms.CharField(label = '确认密码', widget = forms.PasswordInput(attrs = {'class' : 'confirm_password'}))

class UploadForm(forms.Form):
    head160 = forms.FileField(label = "选择一张你喜欢的照片")
